package com.vhly.classfile;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public abstract class CPEntry {
    public static final int TYPE_UTF8 = 1;
    public static final int TYPE_UNICODE = 2;
    public static final int TYPE_INTEGER = 3;
    public static final int TYPE_FLOAT = 4;
    public static final int TYPE_LONG = 5;
    public static final int TYPE_DOUBLE = 6;
    public static final int TYPE_CLASS = 7;
    public static final int TYPE_STRING = 8;
    public static final int TYPE_FIELD = 9;
    public static final int TYPE_METHOD = 10;
    public static final int TYPE_INTERFACE = 11;
    public static final int TYPE_NAMEANDTYPE = 12;
    public static final int LEN_UTF8 = 0;
    public static final int LEN_UNICODE = 0;
    public static final int LEN_INTEGER = 4;
    public static final int LEN_FLOAT = 4;
    public static final int LEN_LONG = 8;
    public static final int LEN_DOUBLE = 8;
    public static final int LEN_CLASS = 2;
    public static final int LEN_STRING = 2;
    public static final int LEN_FIELD = 4;
    public static final int LEN_METHOD = 4;
    public static final int LEN_INTERFACE = 4;
    public static final int LEN_NAMEANDTYPE = 4;

    protected int cpIndex;

    public int getCpIndex() {
        return cpIndex;
    }

    public void setCpIndex(int cpIndex) {
        this.cpIndex = cpIndex;
    }

    public abstract void read(DataInputStream datainputstream)
            throws IOException;

    public abstract void write(DataOutputStream dataoutputstream)
            throws IOException;

    public abstract int getType();

    /**
     * 比较指定元素是否和自身相等
     * @param e CPEntry
     * @return 0 equals -1 no
     */
    public abstract boolean equalsTo(CPEntry e);
}